package com.my.java8;

import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.Month;
import java.time.Period;
import java.time.temporal.ChronoField;
import java.time.temporal.ChronoUnit;

public class DateExample {

	public static void main(String[] args) {
		LocalDate date = LocalDate.now();
		
		System.out.println(date);
		
		int year = date.get(ChronoField.YEAR);
		int month = date.get(ChronoField.MONTH_OF_YEAR);
		int day = date.get(ChronoField.DAY_OF_MONTH);
		
		LocalDate date2 = LocalDate.parse("2014-03-18");
		LocalTime time2 = LocalTime.parse("13:45:20");
		
		LocalDateTime dt1 = LocalDateTime.of(2014, Month.MARCH, 18, 13, 45, 20);
		LocalDateTime dt2 = LocalDateTime.of(date, time2);
		LocalDateTime dt3 = date.atTime(13, 45, 20);
		LocalDateTime dt4 = date.atTime(time2);
		LocalDateTime dt5 = time2.atDate(date);
		
		Duration d1 = Duration.between(time2, time2);
		Duration d2 = Duration.between(dt1, dt2);
		//Duration d2 = Duration.between(instant1, instant2);
		
		Period tenDays = Period.between(LocalDate.of(2014, 3, 8),
				LocalDate.of(2014, 3, 18));
		
		Duration threeMinutes = Duration.ofMinutes(3);
		Duration threeMinutes2 = Duration.of(3, ChronoUnit.MINUTES);
		Period tenDays2 = Period.ofDays(10);
		Period threeWeeks = Period.ofWeeks(3);
		Period twoYearsSixMonthsOneDay = Period.of(2, 6, 1);
		
		LocalDate date3 = LocalDate.of(2014, 3, 18);
		date3 = date3.with(ChronoField.MONTH_OF_YEAR, 9);
		date3 = date3.plusYears(2).minusDays(10);
		LocalDate date4 = date3.withYear(2011);
		System.out.println(date3);
		System.out.println(date4);

	}

}
